package com.dq.controller.op.opmerchant;

import com.dq.exception.customException.AdminException;
import com.dq.controller.op.opmerchant.in.query.OrgOrderRetureQuery;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import com.dq.domain.orders.UserOrderReturn;
import com.dq.service.AllService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author heshuaijun
 * @date 2019/9/1716:24
 */
@Api(description = "后台 采购退货单管理 ？？？？")
@RestController
@RequestMapping("/sys/orgOrderReture")
public class OrgOrderRetureController extends AllService {

    @ApiOperation("根据条件检索采购退货单列表")
    @PostMapping("/list")
    @RequiresPermissions("sys:orgOrderReture:list")
    public Vo list(@RequestBody OrgOrderRetureQuery orgOrderRetureQuery) throws AdminException {

        Map<String, Object> query = orgOrderRetureQuery.parseMap();
        List<UserOrderReturn> orgOrderList = dao.find(dao.queryAdminHql(UserOrderReturn.class, query), query);
        orgOrderRetureQuery.format();
        PageHelper.startPage(orgOrderRetureQuery.getPage(), orgOrderRetureQuery.getSize());
        PageInfo pageInfo = new PageInfo((List<UserOrderReturn.Vo>) VO.toVOCollection(orgOrderList));
        pageInfo.setTotal(dao.count(dao.countAdminHql(UserOrderReturn.class, query), query));
        return new Vo(pageInfo);
    }

}